package com.mini.demos.webgame.codec;

import org.apache.mina.core.buffer.IoBuffer;

import com.mini.demos.webgame.msg.AbstractGameMsg;
import com.mini.demos.webgame.msg.JobListMsg;
import com.mini.demos.webgame.msg.MsgHead;
import com.mini.demos.webgame.util.CommandConstants;
import com.mini.demos.webgame.util.Constants;

public class JobListDecoder extends AbstractDecoder {

	@Override
	public AbstractGameMsg decodeBody(IoBuffer buffer, MsgHead head) {
		JobListMsg jobListMsg = new JobListMsg();
		jobListMsg.setHead(head);
		try{
			String userName = buffer.getString(Constants.charset.newDecoder());
			jobListMsg.setUserName(userName);
		}catch(Exception e){
			e.printStackTrace();
		}
		return jobListMsg;
	}

	@Override
	public boolean isLegalCommand(int commandId) {
		if(commandId == CommandConstants.JOB_LIST){
			return true;
		}
		return false;
	}

}
